home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / ka9q / expiry / inwindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-09  |  965 b   |  38 lines

  1. /* Check to see if the current time is within a given 'window' */
  2.  
  3. /* Written by Bernie Roehl, May 1990 */
  4.  
  5. /* Exits with 1 if in window, 0 if not, 2 or more if error encountered */
  6.  
  7. #include <stdio.h>
  8. #include <dos.h>
  9.  
  10. char *progname = "INWINDOW";
  11.  
  12. void main(int argc, char *argv[])
  13.     {
  14.     struct time dostime;
  15.     int lh, ll, hh, hl, lowtime, hightime, now;
  16.     if (argc != 2) {
  17.         printf("%s: correct usage is 'INWINDOW hh:mm-hh:mm'\n", progname);
  18.         exit(2);
  19.         }
  20.     if (sscanf(argv[1], "%d:%d-%d:%d", &lh, &ll, &hh, &hl) != 4) {
  21.         printf("%s: invalid syntax in time range... should be hh:mm-hh:mm\n", progname);
  22.         exit(3);
  23.         }
  24.     lowtime = lh * 100 + ll;
  25.     hightime = hh * 100 + hl;
  26.     gettime(&dostime);
  27.     now = dostime.ti_hour * 100 + dostime.ti_min;
  28.     if (lowtime < hightime) {  /* doesn't cross midnight */
  29.         if (now < lowtime || now >= hightime)
  30.             exit(0);
  31.         }
  32.     else {
  33.         if (now < lowtime && now >= hightime)
  34.             exit(0);
  35.         }
  36.     exit(1);
  37.     }
  38.